package com.ruoyi.web.controller.frock;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.frock.FrockSeat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IFrockSeatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工装管理基础Controller
 *
 * @author ruoyi
 * @date 2023-04-20
 */
@Api(tags = "工装管理基础Api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/frock/seat" )
public class FrockSeatController extends BaseController {

    private final IFrockSeatService iFrockSeatService;

    /**
     * 查询工装管理基础列表
     */
    @ApiOperation(value = "查询工装管理基础列表")
    //@PreAuthorize("@ss.hasPermi('frock:seat:list')")
    @GetMapping("/list")
    public TableDataInfo list(FrockSeat frockSeat)
    {
        startPage();
        List<FrockSeat> list = iFrockSeatService.selectList(frockSeat);
        return getDataTable(list);
    }

    /**
     * 导出工装管理基础列表
     */
    //@PreAuthorize("@ss.hasPermi('frock:seat:export')" )
    @Log(title = "工装管理基础" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(FrockSeat frockSeat) {
        LambdaQueryWrapper<FrockSeat> lqw = new LambdaQueryWrapper<FrockSeat>(frockSeat);
        List<FrockSeat> list = iFrockSeatService.list(lqw);
        ExcelUtil<FrockSeat> util = new ExcelUtil<FrockSeat>(FrockSeat. class);
        return util.exportExcel(list, "seat" );
    }

    /**
     * 获取工装管理基础详细信息
     */
    @ApiOperation(value = "获取工装管理基础详细信息")
    //@PreAuthorize("@ss.hasPermi('frock:seat:query')" )
    @GetMapping(value = "/{frockId}" )
    public AjaxResult getInfo(@PathVariable("frockId" ) Long frockId) {
        return AjaxResult.success(iFrockSeatService.getByIdFr(frockId));
    }

    /**
     * 新增工装管理基础
     */
    @ApiOperation(value = "新增工装管理基础")
    //@PreAuthorize("@ss.hasPermi('frock:seat:add')" )
    @Log(title = "工装管理基础" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FrockSeat frockSeat) {
        frockSeat.setCreateBy(SecurityUtils.getUsername());
        frockSeat.setCreateTime(new Date());
        return toAjax(iFrockSeatService.saveFr(frockSeat) ? 1 : 0);
    }

    /**
     * 修改工装管理基础
     */
    @ApiOperation(value = "修改工装管理基础")
    //@PreAuthorize("@ss.hasPermi('frock:seat:edit')" )
    @Log(title = "工装管理基础" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FrockSeat frockSeat) {
        frockSeat.setUpdateBy(SecurityUtils.getUsername());
        frockSeat.setUpdateTime(new Date());
        return toAjax(iFrockSeatService.updateByIdFr(frockSeat) ? 1 : 0);
    }

    /**
     * 删除工装管理基础
     */
    @ApiOperation(value = "删除工装管理基础")
    //@PreAuthorize("@ss.hasPermi('frock:seat:remove')" )
    @Log(title = "工装管理基础" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{frockIds}" )
    public AjaxResult remove(@PathVariable Long[] frockIds) {
        return toAjax(iFrockSeatService.removeByIds(Arrays.asList(frockIds)) ? 1 : 0);
    }
}
